home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13083 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: li.net!jeremy
  2. From: jeremy@newshost.li.net (Jeremy Markman)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help: array of ptrs to structures
  5. Date: 4 Apr 1996 14:18:43 GMT
  6. Organization: LI Net (Long Island Network)
  7. Message-ID: <4k0lo3$hn6@linet06.li.net>
  8. References: <Pine.SOL.3.91-941213.960403155531.22205C-100000@altair.dur.ac.uk>
  9. NNTP-Posting-Host: linet04.li.net
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Ed Wiles (E.D.Wiles@durham.ac.uk) wrote:
  13. : 1) How do I hard-code, for example, the third person in the array to be:
  14. :    lastname = "Adcock";  firstname = "Lucy";  phone = "(01623) 943086"; ?
  15.  
  16. :    *phone_book[2] = {"Adcock", "Lucy", etc.} is not allowed, so do I have to
  17. :    assign each structure member individually?
  18. :    i.e. *phone_book[2]->lastname = "Adcock", etc.
  19.  
  20. strcpy(phone_book[2]->lastname,"Adcock");
  21. but make sure you use malloc() to allocate memory
  22. i.e. phone_book[2] = malloc(sizeof(struct person));
  23. etc...
  24.  
  25. :     go: is there a way of doing this when I declare the variable phone_book,
  26. :     remembering that e.g. int odds[] = {1, 3, 5, 7} is allowed?)
  27.  
  28. yes, that is allowed!
  29.  
  30. : 2) I want to pass the entire array to a function. Do I just pass it as
  31. :    phone_book? Should the function's corresponding formal parameter be
  32. :    struct person *anyname[] ?
  33. Yes, also using struct person **anyname is acceptable...
  34.  
  35.